package com.black.protocol;

public class Response<T> {

    private int code;
    private String msg;
    private T res;

    public Response(int code, String msg, T res) {
        this.code = code;
        this.msg = msg;
        this.res = res;
    }

    public static <T> Response<T> success(){
        return Response.success(null);
    }

    public static <T> Response<T> success(T res){
        return new Response<>(ErrorCode.SUCCESS_OK,res);
    }

    public static <T> Response<T> fail(){
        return Response.fail(ErrorCode.ERROR_UNKNOWN);
    }

    public static <T> Response<T> fail(ErrorCode errorCode){
        return new Response<>(errorCode);
    }

    public static <T> Response<T> response(ErrorCode code,T res){
        return new Response<>(code,res);
    }

    public static <T> Response<T> response(int code,String msg,T res){
        return new Response<>(code,msg,res);
    }

    public Response(ErrorCode errorCode,T res){
        this(errorCode.code,errorCode.msg,res);
    }

    public Response(ErrorCode errorCode){
        this(errorCode,null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getRes() {
        return res;
    }

    public void setRes(T res) {
        this.res = res;
    }
}
